package com.example.easy.excel.demo.controller;

import com.example.easy.excel.demo.servcie.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping("download")
@AllArgsConstructor
@Api(tags = "Excel文件导出")
public class DownloadController {

    @Resource
    private DataService dataService;

    @ApiOperation(value = "模板")
    @GetMapping("example")
    public void example(HttpServletResponse response) {
        try {
            dataService.example(response);
        } catch (Exception e) {
            log.info("example-method-go-wroth:{}", e.getMessage());
        }
    }

    @ApiOperation(value = "数据忽略")
    @GetMapping("demoData")
    public void demoData(HttpServletResponse response) {
        try {
            dataService.demoData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }

    @ApiOperation(value = "复杂头部")
    @GetMapping("complexHeadData")
    public void complexHeadData(HttpServletResponse response) {
        try {
            dataService.complexHeadData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }

    @ApiOperation(value = "数据转换")
    @GetMapping("converterData")
    public void converterData(HttpServletResponse response) {
        try {
            dataService.converterData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }

    @ApiOperation(value = "文本自定义")
    //WriteCellDemoData
    @GetMapping("writeCellDemoData")
    public void writeCellDemoData(HttpServletResponse response) {
        try {
            dataService.writeCellDemoData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }

    @ApiOperation(value = "快速定义列宽")
    //WidthAndHeightData
    @GetMapping("widthAndHeightData")
    public void widthAndHeightData(HttpServletResponse response) {
        try {
            dataService.widthAndHeightData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }


    @ApiOperation(value = "定义标题和内容的背景色和字体")
    //DemoStyleData
    @GetMapping("demoStyleData")
    public void demoStyleData(HttpServletResponse response) {
        try {
            dataService.demoStyleData(response);
        } catch (Exception e) {
            log.info("demoData-method-go-wroth:{}", e.getMessage());
        }
    }

    private void failureResponse(HttpServletResponse response) {
//        response.reset();
//        response.setDateHeader("Cntent-Type", "application/json");
    }
}
